package com.example.permission.myjbm.model;

import com.jbm.jbmsupplier.util.InfomationEntity;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

/**
 *   MyFragment 的model
 */
public class MyFragmentModel{

    //修改时间
    public void modifyDate(InfomationEntity infomationEntity, SimpleDateFormat df){
        Calendar c = Calendar.getInstance(Locale.CHINA);
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int  day = c.get(Calendar.DAY_OF_MONTH);
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        month+=1;
        //时间为设置
        String d2 = df.format(infomationEntity.getUpdateDate());
        String [] arr=d2.split("-");
        //同年
        if(year==Integer.parseInt(arr[0])){
            //同月
            if(month==Integer.parseInt(arr[1])){
                //同日
                if(day==Integer.parseInt(arr[2])){
                    //同时
                    if(hour-Integer.parseInt(arr[3])<1){
                        //显示多少分钟前
                        int ff = minute - Integer.parseInt(arr[4]);
                        if(ff==0){
                            infomationEntity.setDealtime("刚刚");
                        }else {
                            infomationEntity.setDealtime(ff + "分钟前");
                        }
                    }else{
                        //显示多少小时前
                        int hours = hour - Integer.parseInt(arr[3]);
                        infomationEntity.setDealtime(hours+"小时前");
                    }
                }else{
                    //不同日
                    infomationEntity.setDealtime("0");
                }
            }else{
                //不同月
                infomationEntity.setDealtime("0");
            }
        }else{
            //不同年
            infomationEntity.setDealtime("0");
        }
    }


}
